package org.example.cet.demos.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.AudioDto;
import org.example.cet.demos.domain.po.Audio;
import org.example.cet.demos.mapper.AudioMapper;
import org.example.cet.demos.service.IAudioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AudioServiceImpl extends ServiceImpl<AudioMapper, Audio> implements IAudioService {
    @Autowired
    private AudioMapper audioMapper;

    @Override
    public PageBean getList(Integer page, Integer pageSize) {
        Long count = audioMapper.count();
        Integer start = (page - 1) * pageSize;
        List<AudioDto> audioDtoList = audioMapper.getList(start, pageSize);
        PageBean pageBean = new PageBean(count, audioDtoList);
        return pageBean;
    }

    @Override
    public List<AudioDto> findByTitle(String audioTitle) {
        return audioMapper.findByTitle(audioTitle);
    }
}

